package cn.jdy.anquan.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.entity.Report;
import cn.jdy.anquan.service.ReportService;
import cn.jdy.common.constant.GlobalConstant;
import cn.jdy.common.ctrl.BaseCtrl;

/**
 * 举报管理
 * Created by hk_ti on 2015/6/14.
 */
@Controller
@RequestMapping("/report")
public class ReportCtrl extends BaseCtrl {

    @Autowired
    private ReportService reportService;

    @RequestMapping("/list")
    public ModelAndView list() {
        ModelAndView mv = new ModelAndView("/report/reportList.jsp");
        mv.addObject("classList", confService.queryByType(GlobalConstant.TYPE_REPORT, 0L));//举报类型
        return mv;
    }

    @RequestMapping("/delete/{id}")
    public ModelAndView delete(@PathVariable Long id) {
        reportService.delete(id);
        return list();
    }

    /**
     *
     * @param report
     * @param fromDate
     * @param toDate
     * @return
     */
    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(Report report, String fromDate, String toDate) {
        Map<String, Object> resp = reportService.queryByPage(report, fromDate, toDate);
        resp.put("classList", confService.queryByType(GlobalConstant.TYPE_BUSINESS, 0L));
        return resp;
    }

    /**
     * 修改举报信息状态
     * @return
     */
    @RequestMapping("/updateStatus")
    @ResponseBody
    public Map<String, Object> updateStatus(Long id, Integer status) {
        Map<String, Object> resp = new HashMap<>();
        reportService.update(id, "status", status);
        resp.put("statusCode", 200);
        return resp;
    }
}
